<style>
.setimg{
	margin:-2px 5px 0 0 
}
</style>
<div class="row-fluid">
	<a style="border:1px solid #ccc" class="block-heading" data-toggle="collapse">列表数据</a>
    <div class="well">
	    <div class="btn-toolbar">
	    <button class="btn btn-primary ifrm" data-url="/cate/addcate" data-width="720" data-height="420" data-title="添加分类" data-params="" style="float:right;padding:3px 6px">添加分类</button>
		    <form>
		    	<label style="display: inline;">分类名称：</label><input class="input input-medium" type="text" name="catename" value="<?=I('get.catename')?>" />
		    	<input type="hidden" value="<?=I('get.res')?>" name="res" />
		    	<button class="btn btn-info" style="margin:-9px 0 0 15px"><i class="icon-search"></i> 搜索</button>
		    </form>
		</div>
		<hr>
		<table class="table">
		      <thead>
		        <tr>
		          <th style="text-align:left">分类名称</th>
		          <th style="text-align:center">分类图片</th>
		          <th style="text-align:center">包含子类</th>
		          <th style="text-align:center">添加时间</th>
		      	  <th style="text-align:center">操作</th>
		        </tr>
		      </thead>
		      <tbody>
		      	<?php if($cateList){foreach($cateList AS $key=>$val){ ?>
		        <tr class="tr<?=$val['cate_id']?>"> 
		          <td style="text-align:left;vertical-align:middle"><?=$val['levels'] ? '<a class="pcate" href="javascript:void(0)" data-cateid='.$val["cate_id"].'><img src="/statics/images/tv-expandable.gif" class="setimg" /></a>' : ''?><?=$val['cate_name']?></td>
		          <td style="text-align:center;vertical-align:middle"><img style="width:50px;height:50px" src="<?=transUrl($val['logo_url'])?>" /></td>
		          <td style="text-align:center;vertical-align:middle"><?=$val['levels'] ?: '-'?></td>
		          <td style="text-align:center;vertical-align:middle"><?=date('Y-m-d',$val['add_at'])?></td>
		          <td style="text-align:center;vertical-align:middle">
		              <a class="ifrm btn btn-info" href="javascript:void(0)" data-url="/cate/addcate" data-width="720" data-height="420" data-title="修改分类" data-params="cateid/<?=$val['cate_id']?>" style="padding: 0px 4px;"><i class="icon-pencil"></i></a>&nbsp;&nbsp;
		              <a  style="padding: 0px 4px;" href="/cate/deletecate?cateid=<?=$val['cate_id']?>" class="decate btn btn-danger" data-cateid="<?=$val['cate_id']?>" role="button" data-toggle="modal"><i class="icon-remove"></i></a>
		          </td>
		        </tr>
		        <?php }}?>
		      </tbody>
		   </table>
	</div>
</div>
<script>
$(function(){
	$('.pcate').live('click',function(){
		_this = $(this);$('#setAjaxImg').remove();
		if(_this.attr('ts') > 0){
			$('.append'+_this.data('cateid')).hide();
			_this.html('<img src="/statics/images/tv-expandable.gif"  class="setimg"  />');
			_this.attr('ts','0');
			return false;
		}
		_this.html('<img id="setAjaxImg" src="/statics/images/ajax_loading.gif" style="margin-right:2px" />');
		$.get('/cate/index',{'ajaxFrom':'1','cateid':$(this).data('cateid')},function(data){
			dd = data;
			$('#setAjaxImg').remove();
			if(data.length){
				var html = '';
				for(var i=0;i<data.length;i++){
					html += '<tr class="append'+_this.data('cateid')+' '+_this.parents('tr').attr('class')+'"><td>&nbsp;&nbsp;&nbsp;'+(_this.data("level") ? "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" : "")+'└ <a class="pcate" href="javascript:void(0)" data-level="last" data-cateid='+data[i].cate_id+'>'+(data[i].iSon > 0 ? "<img src='/statics/images/tv-expandable.gif'  class='setimg'  />" : "<b> </b>")+'</a>'+data[i].cate_name+'</td><td style="text-align:center"><img src="'+data[i].logo_url+'" style="width:40px;height:40px" /></td><td style="text-align:center">'+data[i].levels+'</td><td style="text-align:center">'+data[i].add_at+'</td><td style="text-align:center"><a style="padding: 0px 4px;" class="ifrm btn btn-info" href="javascript:void(0)" data-url="/cate/addcate" data-width="800" data-height="400" data-title="修改分类" data-params="cateid/'+data[i].cate_id+'"><i class="icon-pencil"></i></a>&nbsp;&nbsp;<a href="/cate/deletecate?cateid='+data[i].cate_id+'" class="decate btn btn-danger" style="padding: 0px 4px;" role="button" data-toggle="modal"><i class="icon-remove"></i></a></td></tr>';
				}
				$(html).insertAfter(_this.parents('tr'))
				_this.html('<img src="/statics/images/tv-collapsable.gif"  class="setimg"  />');
				_this.attr('ts','1');
			}else{
				_this.html('<img src="/statics/images/tv-expandable.gif"  class="setimg"  />');
				showmsg('没有子分类数据');
			}
		},'json');
	});
	$('.decate').live('click',function(){
		if(!window.confirm('删除分类将同时删除该分类下的所有子分类 ?')){
			return false;
		}
		window.location = $(this).attr('href');
	});
})
</script>